package MyArrayList;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class TestDemo {
    public static List<Character> func(String str1,String str2){
        ArrayList<Character> arrayList=new ArrayList<>();
        for(int i=0;i<str1.length();i++){

            char ch=str1.charAt(i);
            if(!(str2.contains(ch+""))){
                arrayList.add(ch);
            }

        }
        return arrayList;
    }

    public static void main(String[] args) {

        MyArrayList arrayList=new MyArrayList();
        arrayList.add(0);
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(3);
        arrayList.add(4);
        arrayList.add(5);

        arrayList.display();
        System.out.println();

        System.out.println("删除5");
        arrayList.remove(5);
        arrayList.display();



    }
    public static void main4(String[] args) {


      List<Character> characters=TestDemo.func("welcome to cvte","come");

//        System.out.println(characters);

        for (char ch:characters
             ) {
            System.out.print(ch+"");
        }
        System.out.println("");
        Iterator<Character> iterator= characters.iterator();
        while (iterator.hasNext()){

            System.out.print(iterator.next()+"");
        }
    }


    public static void main3(String[] args) {


        ArrayList<Integer>   arrayList=new ArrayList<>();
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(3);
        arrayList.add(4);

        //1.遍历方式
        System.out.println(arrayList);
        //2.第二种遍历方式for

        for (int i=0;i<arrayList.size();i++){

            System.out.println(arrayList.get(i));
        }
        System.out.println();

        //3.for-each

        for (int x:arrayList
             ) {
            System.out.println(x+" ");
        }
        //4.迭代器
       Iterator<Integer> it= arrayList.iterator();
        while (it.hasNext()){
            System.out.println(it.next()+" ");
        }
        //5
        ListIterator<Integer> listIterator=arrayList.listIterator();
        while (listIterator.hasNext()){

            System.out.println(listIterator.next()+"");
        }

        //6.从后向前打印

        ListIterator<Integer> it3=arrayList.listIterator(arrayList.size());

        while(it3.hasPrevious()){

            System.out.println(it3.previous());
        }




    }
    public static void main2(String[] args) {

        ArrayList<Integer> arrayList=new ArrayList();

        arrayList.add(1);
       int a= arrayList.size();
        System.out.println(a);

    }
    public static void main1(String[] args) {

        MyArrayList myArrayList=new MyArrayList();


        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(3);
        myArrayList.add(4);
        myArrayList.add(5);
        myArrayList.add(6);
//        myArrayList.add(3,5);
       /* myArrayList.add(8,5);*/
        myArrayList.display();
        System.out.println(myArrayList.contains(5));

    }
}
